# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/13 12:13
from PyQt5.Qt import *


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QColorDialog学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		# self.setStyleSheet('background-color:red;')
		# self.setStyleSheet('background-color:rgb(100,200,150);')

		# cd = QColorDialog(QColor(200, 100, 150), self)
		# cd.setWindowTitle('选择一个好看颜色')
		# def color():
		# 	palette = QPalette()
		# 	# palette.setColor(QPalette.Background, cd.selectedColor())
		# 	palette.setColor(QPalette.Background, cd.currentColor())
		# 	self.setPalette(palette)
		#
		# # cd.colorSelected.connect(color)
		# cd.currentColorChanged.connect(color)
		# cd.setOptions(QColorDialog.NoButtons | QColorDialog.ShowAlphaChannel)
		# cd.show()

		btn = QPushButton(self)
		btn.move(100,100)
		btn.setText('按钮')

		def test():
			# color = QColorDialog.getColor(QColor(10,10,200),self,'选择颜色')
			# print(color)

			cd = QColorDialog(self)
			cd.setOption(QColorDialog.NoButtons)

			def sel_color(color):
				palette = QPalette()
				palette.setColor(QPalette.ButtonText, color)
				btn.setPalette(palette)

			# cd.colorSelected.connect(sel_color)
			cd.currentColorChanged.connect(sel_color)
			cd.show()


		# btn.clicked.connect(lambda :print(QColorDialog.customCount()))
		btn.clicked.connect(test)

		# cd.open(color)
		# if cd.exec():
		# 	color()


if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())
